{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Welcome to AdalFlow 🤗\n",
    "AdalFlow is your go-to library for building and auto-optimizing LLM task pipelines. We're dedicated to providing an exceptional LLM application development experience.\n",
    "\n",
    "For questions or support, [join our Discord community](https://discord.gg/ezzszrRZvT).\n",
    "\n",
    "⭐ [Star us on GitHub!](https://github.com/SylphAI-Inc/AdalFlow) ⭐\n",
    "\n",
    "### Quick Links\n",
    "* [GitHub Repository](https://github.com/SylphAI-Inc/AdalFlow)\n",
    "* [Full Tutorials](https://adalflow.sylph.ai/index.html#)\n",
    "* [Developer Notes](https://adalflow.sylph.ai/tutorials/index.html)\n",
    "* [Use Cases](https://adalflow.sylph.ai/use_cases/index.html)\n",
    "\n",
    "### Authors\n",
    "This notebook was created by [Nicholas Fleischhauer](https://www.linkedin.com/in/unobtainiumrock)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import clear_output\n",
    "\n",
    "!pip install -U adalflow[mistralai]\n",
    "\n",
    "clear_output()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Some Initial Setup\n",
    "\n",
    "The following will set up some logging and prompt you to provide API keys for the client we are integrating."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 😇 Have Fun!\n",
    "\n",
    "Let's get started!  🚀\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "API keys have been set.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from getpass import getpass\n",
    "\n",
    "MISTRAL_API_KEY = getpass(\"Please enter your Mistral API key:\")\n",
    "\n",
    "os.environ[\"MISTRAL_API_KEY\"] = MISTRAL_API_KEY\n",
    "\n",
    "print(\"API keys have been set.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Mistral] Response: Machine learning is a subset of artificial intelligence (AI) that focuses on the development of algorithms and statistical models that enable computers to perform specific tasks without explicit instructions, relying on patterns and inference instead. Here are some key concepts to help understand machine learning:\n",
      "\n",
      "1. **Learning from Data**: Machine learning algorithms learn from data. This means that you provide the algorithm with a set of data, and it analyzes this data to find patterns, make predictions, or assist in decision-making.\n",
      "\n",
      "2. **Types of Machine Learning**:\n",
      "   - **Supervised Learning**: In this type, the algorithm is trained on a labeled dataset, which means that each training example is paired with an output label. The goal is to learn a mapping from inputs to outputs. For example, predicting housing prices based on features like size, location, etc.\n",
      "   - **Unsupervised Learning**: Here, the algorithm is given data without explicit instructions on what to do with it. The goal is to infer the natural structure present within this set of data points. For example, clustering customers based on their purchasing behavior.\n",
      "   - **Reinforcement Learning**: This involves training algorithms using a system of rewards and punishments. The algorithm learns to make decisions by interacting with an environment and receiving feedback. For example, a bot learning to play a game.\n",
      "\n",
      "3. **Training and Testing**: Machine learning models are typically trained on a subset of data (training set) and then evaluated on a different subset (testing set) to ensure that the model can generalize well to new, unseen data.\n",
      "\n",
      "4. **Features and Labels**: In supervised learning, data is represented by features (input variables) and labels (output variables). Features are the characteristics or attributes of the data, while labels are the outcomes or targets that the model aims to predict.\n",
      "\n",
      "5. **Model Evaluation**: After training a model, it's important to evaluate its performance using various metrics such as accuracy, precision, recall, F1 score, etc. This helps in understanding how well the model is performing and where it can be improved.\n",
      "\n",
      "6. **Overfitting and Underfitting**: These are common challenges in machine learning. Overfitting occurs when a model learns the training data too well, including noise and outliers, and performs poorly on new data. Underfitting happens when a model is too simple to capture the underlying patterns in the data.\n",
      "\n",
      "7. **Applications**: Machine learning has a wide range of applications, including image and speech recognition, natural language processing, recommendation systems, fraud detection, and more.\n",
      "\n",
      "In essence, machine learning is about teaching computers to learn from and make predictions or decisions based on data, rather than being explicitly programmed for specific tasks.\n"
     ]
    }
   ],
   "source": [
    "from adalflow.components.model_client import MistralClient\n",
    "import adalflow as adal\n",
    "\n",
    "generator = adal.Generator(\n",
    "    model_client=MistralClient(),\n",
    "    model_kwargs={\n",
    "        \"model\": \"mistral-large-latest\",\n",
    "        \"temperature\": 0.7,\n",
    "        \"max_tokens\": 2000,\n",
    "    },\n",
    ")\n",
    "\n",
    "prompt_kwargs = {\"input_str\": \"Explain the concept of machine learning.\"}\n",
    "\n",
    "response = generator(prompt_kwargs)\n",
    "\n",
    "if response.error:\n",
    "    print(f\"[Mistral] Generator Error: {response.error}\")\n",
    "else:\n",
    "    print(f\"[Mistral] Response: {response.data}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
